package com.yms.controller;



import com.yms.pojo.Admin;
import com.yms.pojo.Menu;
import com.yms.pojo.Result;
import com.yms.pojo.TreeResult;
import com.yms.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2020-03-20
 */
@Controller
@RequestMapping("/menu")
public class MenuController {
    //声明业务层属性
    @Autowired
    private IMenuService menuService;
    //声明单元方法:加载菜单信息
    @ResponseBody
    @RequestMapping("menuInfo")
    public List<TreeResult> menuInfo(@RequestParam(defaultValue = "0") String id, HttpSession session){
        //处理请求
            //获取session中的用户的Id
            Admin admin= (Admin) session.getAttribute("admin");
            Integer aid=admin.getAid();
            //调用业务层获取当前登录的用户的菜单信息
            List<TreeResult> list = menuService.selMenuInfoService(id, aid);
        //响应结果
            return list;
    }
    //加载全部菜单信息
    @RequestMapping("menuInfoALL")
    @ResponseBody
    public List<TreeResult> menuInfoALL(@RequestParam(defaultValue = "0") String id){
        return menuService.menuInfoALL(id);
    }
    //增加菜单
    @RequestMapping("addMenu")
    @ResponseBody
    private Result addMenu(Menu menu){
        return menuService.addMenu(menu);
    }
    //修改菜单
    @RequestMapping("editMenu")
    @ResponseBody
    public Result editMenu(Menu menu){
        return menuService.updaMenu(menu);
    }
    //删除指定菜单
    @ResponseBody
    @RequestMapping("deleteMenuById")
    public Result deleteMenuById(Integer mid){
        return menuService.deleteMenuById(mid);
    }

}

